<style lang="scss" scoped>
@import "~@/assets/styles/mixin.scss";
@import "~@/assets/styles/variables.scss";

.app-main {
  min-height: calc(100vh - 84px);
}

.navbar {
  height: 50px;
  overflow: hidden;
  position: relative;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 21, 41, .08);

  .hamburger-container {
    line-height: 46px;
    height: 100%;
    float: left;
    cursor: pointer;
    transition: background .3s;
    -webkit-tap-highlight-color: transparent;

    &:hover {
      background: rgba(0, 0, 0, .025)
    }
  }

  .breadcrumb-container {
    float: left;
    line-height: 60px;
    padding-left: 40px;
  }

  .errLog-container {
    display: inline-block;
    vertical-align: top;
  }

  .search-menu {
    line-height: 60px !important;
    margin-right: 20px;
  }

  .right-menu {
    float: right;
    height: 100%;
    line-height: 50px;

    &:focus {
      outline: none;
    }

    .right-menu-item {
      display: inline-block;
      padding: 0 8px;
      height: 100%;
      font-size: 18px;
      color: #5a5e66;
      vertical-align: text-bottom;

      &.hover-effect {
        cursor: pointer;
        transition: background .3s;

        &:hover {
          background: rgba(0, 0, 0, .025)
        }
      }
    }

    .avatar-container {
      margin-right: 30px;

      .avatar-wrapper {
        margin-top: 5px;
        position: relative;

        .user-avatar {
          cursor: pointer;
          width: 40px;
          height: 40px;
          border-radius: 10px;
        }

        .el-icon-caret-bottom {
          cursor: pointer;
          position: absolute;
          right: -20px;
          top: 18px;
          font-size: 12px;
        }
      }
    }
  }
}

.dept-main-container {
  height: 100%;
  overflow: hidden;
  position: relative;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
}

.main-containe-header {
  max-height: 84px;
  border-bottom: 1px solid #d8dce5;
}
.app-container{
  //min-height: 300px;
  height: 90vh;
}
</style>
<template>
  <div
    :class="classObj"
    class="app-wrapper"
  >
    <div class="dept-main-container">
      <div class="main-containe-header">
        <div class="navbar">
          <div class="hamburger-container"></div>
          <div class="breadcrumb-container">{{ $t('common.selectDept') }}</div>
          <div class="right-menu">
            <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click">
              <div class="avatar-wrapper">
                {{ $t('common.welcome',{name: '',deptName: ''}) }}
                <i class="el-icon-caret-bottom"/>
              </div>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item divided @click.native="logout">
                  <span>{{ $t('common.exit') }}</span>
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>

        </div>
      </div>
      <div class="app-main">
        <div class="app-container">
          <ht-table
            ref="dataTable"
            :reqConfig="reqConfig"
            :showRightToolbar="false"
            :dictMap="dictMap"
            :tableBindColumns="tableBindColumns"
            :showSearch="showSearch"
            :opButtonList="opButtonList"
            :showExport="false"
          >
          </ht-table>
        </div>
      </div>
    </div>
  </div>

</template>

<script>
import ResizeMixin from "@/layout/mixin/ResizeHandler";
import variables from "@/assets/styles/variables.scss";
import {userDeptRoleConfig, loginByDeptId} from "@/api/authority_app/dept";
import {listPageMixin} from "@/libs/listPageMixin";

export default {
  components: {
  },
  mixins: [ResizeMixin, listPageMixin],
  data() {
    return {
      reqConfig: userDeptRoleConfig,
      // 列信息
      tableBindColumns: [
        {label: `${ this.lang('authority.userInfo.form.userId') }`, prop: "userId"},
        {label: `${ this.lang('authority.userInfo.form.userName') }`, prop: "userName"},
        {label: `${ this.lang('authority.userInfo.form.deptName') }`, prop: "deptName"},
        {
          label: `${ this.lang('authority.userInfo.form.role') }`, prop: "roleName",
          formatter: (row, value, index) => {
            let va = "";
            for (let index in row.roles) {
              if (index < row.roles.length - 1) {
                va += row.roles[index].roleName + ",";
              } else {
                va += row.roles[index].roleName;
              }
            }
            return va;
          }
        },
        {
          label: `${ this.lang('authority.userInfo.form.type') }`, prop: "type",formatter: (row, value, index) => {
           return value == 1 ? `${ this.lang('common.own') }` : `${ this.lang('common.appoint') }`
          }
        },
        {
          label: `${ this.lang('common.operate') }`, type: 'operate', buttonList: (rowData) => [
            {
              label: `${ this.lang('common.login') }`,
              doFunc: (rowData) => {
                this.loginIn(rowData.credentialId)
              }
            }
          ]
        }
      ],
    };
  },
  computed: {
    classObj() {
      return {};
    },
    variables() {
      return variables;
    },
  },
  created() {
  },
  methods: {
    loginIn(id) {

      loginByDeptId(id).then(res => {

        this.$store.dispatch("GetInfo").then((res) => {

          this.$router.replace({path: "/index"}).catch(() => {
          })
        })
      });
    },
    async logout() {
      this.$confirm(`${this.$i18n.t('common.exitSystem')}`, `${this.$i18n.t('common.tip')}`, {
        confirmButtonText: `${this.$i18n.t('common.confirm')}`,
        cancelButtonText: `${this.$i18n.t('common.cancel')}`,
        type: 'warning'
      }).then(() => {
        this.$store.dispatch('LogOut').then(() => {
          location.href = '/index';
        })
      }).catch(res => {
      })
    }
  }
};
</script>
